<?php

/*
用户主题设置model 包含用户主题usrtheme,官方主题theme,气泡bubble三个表操作
*/

class themeModel extends Model
{
	private $utb='usrtheme';
	private $tb='theme';
	private $bb='bubble';
	private $sb='sceneshow';
	
	//获取用户主题设置
	public function getUsertheme($uid)
	{
		$theme=$this->db->getRow("select * from $this->utb where uid=$uid");
		//var_dump($theme);
		if($theme)
		{
			
			$bub=$this->db->getRow("select bubble_img,bubble_imgshow,bubble_bgimg from $this->bb where id=".$theme['bubbleid']);
			if($bub)
			{
				$theme=array_merge($theme,$bub);
			}
			return $theme;
		}
		return false;
	}

	//根据属性设置用户主题
	public function setUsertheme($uid,$data)
	{
		if($this->db->update($this->utb,$data,$uid))
		{
			return $this->db->affect_row();
		}
		return false;
	}

	
	//将用户主题设置为官方主题
	public function setTheme($uid,$themeid)
	{
		$tobj=$this->db->getRow("select bgcolor,bgimg,skinopacity,glassopacity,openglass from $this->tb where id=$themeid");
		if($tobj)
		{
			if($this->setUsertheme($uid,$tobj))
			{
				return true;
			}
			return false;
		}
		return false;
	}
	
	//获取气泡设置
	public function getbubble($id)
	{
		$sql="select * from $this->bb where id=$id";
		return $this->db->getRow($sql);
	}
	
	//获取部分/所有气泡
	public function getbubbles($num=0)
	{
		$sql="select * from $this->bb";
		if($num>0)
		{
			$sql.=" limit ".$num;
		}
		return $this->db->getAll($sql);
	}
	
	//获取官方主题设置
	public function getTheme($id)
	{
		$sql="select * from $this->tb where id=$id";
		return $this->db->getRow($sql);	
	}

	//获取多个官方主题设置
	public function getThemes($num)
	{
		$sql="select * from $this->tb limit $num";
		return $this->db->getAll($sql);
	}


	//获取推荐的N个场景秀
	public function getreScene($num=4)
	{
		$sql="select * from $this->sb where recommend=1 limit ".$num;
		return $this->db->getAll($sql);
	}

	//获取热门的N个场景秀
	public function gethotScene($num=12)
	{
		$sql="select * from $this->sb order by usernum desc limit ".$num;
		return $this->db->getAll($sql);
	}



}